package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.entity.Activity;
import com.qk.management.anno.LogOperation;
import com.qk.management.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 16778
 * @date 2025/10/7 19:46
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/activities")
public class ActivityController {
    @Autowired
    private ActivityService activityService;

    @GetMapping
    public Result page(@RequestParam(required = false)Integer channel,
                       @RequestParam(required = false)Integer type,
                       @RequestParam(required = false)Integer status,
                       Integer page, Integer pageSize){
        PageResult<Activity> pageResult = activityService.page(channel,type,status,page,pageSize);
        return Result.success(pageResult);
    }

    @LogOperation
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("需要删除的活动的id:{}",id);
        activityService.delete(id);
        return Result.success();
    }

    @LogOperation
    @PostMapping()
    public Result insert(@RequestBody Activity activity){
        log.info("需要添加的活动:{}",activity);
        activityService.insert(activity);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id){
        log.info("需要查询的id:{}",id);
        Activity activity = activityService.selectById(id);
        return Result.success(activity);
    }

    @LogOperation
    @PutMapping
    public Result update(@RequestBody Activity activity){
        log.info("需要更新的活动:{}",activity);
        activityService.update(activity);
        return Result.success();
    }

    @GetMapping("/type/{type}")
    public Result selectByType(@PathVariable Integer type){
        log.info("需要查询的类型:{}",type);
        List<Activity> list = activityService.selectByType(type);
        return Result.success(list);
    }

    @GetMapping("/list")
    public Result findAll(){
        List<Activity> list = activityService.findAll();
        return Result.success(list);
    }
}
